﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" 
AutoEventWireup="true" CodeFile="rptIncome.aspx.cs" 
Inherits="SIPO.Web.Reports.Transaction.rptIncome" %>

<asp:Content ID="Content1" ContentPlaceHolderID="body" Runat="Server">

    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />

    <script src="<%= ResolveUrl("~/scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.wrapper.js") %>" type="text/javascript"></script>

    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
   <script type="text/javascript">
       $(function () {
           //populate data sector
           var listSektor = [];
           var handlerUrlSector = '<%= ResolveUrl("~/AjaxHandler/Loaddata/getsector.ashx") %>';
           //var handlerUrlSector = '<%= ResolveUrl("~/AjaxHandler/Loaddata/getPenerimaan.ashx") %>';
           $.ajax({
               type: 'POST',
               url: handlerUrlSector,
               contentType: 'application/json',
               dataType: 'json',
               success: function (datas) {
                   $.each(datas, function (i, data) {
                       listSektor.push(data.SectorID + "-" + data.SectorName);
                   });
               },
               error: function () {
                   alert('Error getSector!');
               }
           });

           function split(val) {
               return val.split(/,\s*/);
           }
           function extractLast(term) {
               return split(term).pop();
           }


           $("#txtSektor")
           // don't navigate away from the field on tab when selecting an item
			.bind("keydown", function (event) {
			    //alert(availableTags);
			    if (event.keyCode === $.ui.keyCode.TAB &&
						$(this).data("ui-autocomplete").menu.active) {
			        event.preventDefault();
			    }
			})
			.autocomplete({
			    minLength: 0,
			    source: function (request, response) {
			        // delegate back to autocomplete, but extract the last term
			        response($.ui.autocomplete.filter(
						listSektor, extractLast(request.term)));
			    },
			    focus: function () {
			        // prevent value inserted on focus
			        return false;
			    },
			    select: function (event, ui) {
			        var terms = split(this.value);
			        // remove the current input
			        terms.pop();
			        // add the selected item
			        terms.push(ui.item.value);
			        // add placeholder to get the comma-and-space at the end
			        terms.push("");
			        this.value = terms.join(", ");
			        return false;
			    }
			});
       });
	</script> 
   <script type="text/javascript">
       $(document).ready(function () {
           $('#txtSektor').blur(function () {
               if ($('#txtSektor').val() != "" && $('#txtSektor').val() != "pilih sektor...")
                {
                   $(function () {
                       var list = $('#txtSektor').val();
                       //populate data sub sector
                       var listSubSektor = [];
                       var temp = [];
                       var temp1 = [];
                       temp = list.split(',');
                       if (temp.length > 0) {
                           for (i = 0; i < temp.length - 1; i++) {
                               temp1.push(temp[i].split('-', 1));
                           }

                           var gabung = temp1.join(',');
                           var parameter = "where recSector.SectorID in(" + gabung + ")";

                           var handlerUrlSubSector = '<%= ResolveUrl("~/AjaxHandler/Loaddata/getsubsector.ashx?method=multipleSectorID&param=' + parameter + '") %>';

                           $.ajax({
                               type: 'POST',
                               url: handlerUrlSubSector,
                               contentType: 'application/json',
                               dataType: 'json',
                               success: function (datas) {
                                   $.each(datas, function (i, data) {
                                       listSubSektor.push(data.SubSectorID + "-" + data.SubSectorName);
                                   });
                               },
                               error: function () {
                                   alert('Error getSubSector!');
                               }
                           });

                           function split(val) {
                               return val.split(/,\s*/);
                           }
                           function extractLast(term) {
                               return split(term).pop();
                           }


                           $("#txtSubSektor")
                           // don't navigate away from the field on tab when selecting an item
			.bind("keydown", function (event) {
			    //alert(availableTags);
			    if (event.keyCode === $.ui.keyCode.TAB &&
						$(this).data("ui-autocomplete").menu.active) {
			        event.preventDefault();
			    }
			})
			.autocomplete({
			    minLength: 0,
			    source: function (request, response) {
			        // delegate back to autocomplete, but extract the last term
			        response($.ui.autocomplete.filter(
						listSubSektor, extractLast(request.term)));
			    },
			    focus: function () {
			        // prevent value inserted on focus
			        return false;
			    },
			    select: function (event, ui) {
			        var terms = split(this.value);
			        // remove the current input
			        terms.pop();
			        // add the selected item
			        terms.push(ui.item.value);
			        // add placeholder to get the comma-and-space at the end
			        terms.push("");
			        this.value = terms.join(", ");
			        return false;
			    }
			});
                       } else {
                           alert('sektor harus diisi dulu!');
                       }
                   });
               }
           });
       });
   </script>
   <script type="text/javascript">
       $(document).ready(function () {
           function pisahkan(control) {
               var list = control;
               var temp = [];
               var temp1 = [];
               temp = list.split(',');
               if (temp.length > 0) {
                   for (i = 0; i < temp.length - 1; i++) {
                       temp1.push(temp[i].split('-', 1));
                   }
               }
               var gabung = temp1.join(',');
               return gabung;
           }

           $('#txtSubSektor').blur(function () {
               if ($('#txtSubSektor').val() != "" && $('#txtSubSektor').val() != "pilih sub sektor...") {
                   $(function () {

                       var listSector = $('#txtSektor').val();
                       var listSubSector = $('#txtSubSektor').val();
                       //populate data sub sub sector
                       var listSubSubSektor = [];
                       var gabungSector = pisahkan(listSector);
                       var gabungSubSector = pisahkan(listSubSector);

                       if (gabungSector != null && gabungSubSector != null) {

                           var parameter = "where recSector.SectorID in(" + gabungSector + ") and recSubSector.SubSectorID in(" + gabungSubSector + ")";


                           var handlerUrlSubSector = '<%= ResolveUrl("~/AjaxHandler/Loaddata/getsubsubsector.ashx?method=multipleSubSubSectorID&param=' + parameter + '") %>';

                           $.ajax({
                               type: 'POST',
                               url: handlerUrlSubSector,
                               contentType: 'application/json',
                               dataType: 'json',
                               success: function (datas) {
                                   $.each(datas, function (i, data) {
                                       listSubSubSektor.push(data.SubSubSectorID + "-" + data.SubSubSectorName);
                                   });
                               },
                               error: function () {
                                   alert('Error getSubSubSector!');
                               }
                           });

                           function split(val) {
                               return val.split(/,\s*/);
                           }
                           function extractLast(term) {
                               return split(term).pop();
                           }


                           $("#txtSubSubSektor")
                           // don't navigate away from the field on tab when selecting an item
			.bind("keydown", function (event) {
			    //alert(availableTags);
			    if (event.keyCode === $.ui.keyCode.TAB &&
						$(this).data("ui-autocomplete").menu.active) {
			        event.preventDefault();
			    }
			})
			.autocomplete({
			    minLength: 0,
			    source: function (request, response) {
			        // delegate back to autocomplete, but extract the last term
			        response($.ui.autocomplete.filter(
						listSubSubSektor, extractLast(request.term)));
			    },
			    focus: function () {
			        // prevent value inserted on focus
			        return false;
			    },
			    select: function (event, ui) {
			        var terms = split(this.value);
			        // remove the current input
			        terms.pop();
			        // add the selected item
			        terms.push(ui.item.value);
			        // add placeholder to get the comma-and-space at the end
			        terms.push("");
			        this.value = terms.join(", ");
			        return false;
			    }
			});
                       } else {
                           alert('sub sektor harus diisi dulu!');
                       }
                   });
               }
           });
       });
   </script>
   <h2>Laporan Pendapatan</h2>
<table>
   
    <tr>
        <td style="width: 50">Sektor</td>
        <td>:</td>
        <td>
            <input type="text" id="txtSektor" size="75" />
        </td>
    </tr>
    <tr>
        <td style="width: 50">Sub Sektor</td>
        <td>:</td>
        <td>
            <input type="text" id="txtSubSektor" size="75" />
        </td>
    </tr>
    <tr>
        <td style="width: 50">Sub Sub Sektor</td>
        <td>:</td>
        <td>
            <input type="text" id="txtSubSubSektor" size="75" />
        </td>
    </tr>
    <tr>
        <td style="width: 50">Jenis Pungutan</td>
        <td>:</td>
        <td><asp:DropDownList ID="ddlJenisPungutan" runat="server" Width="200"></asp:DropDownList></td>
    </tr>
    <tr>
        <td style="width: 50">Penampilan Informasi</td>
        <td>:</td>
        <td><input type="checkbox" id="cbDetail" />Detail</td>
    </tr>
    <tr>
        <td style="width: 50">Periode</td>
        <td>:</td>
        <td><input type="text" id="txtPeriodeAwal" />-
        <input type="text" id="txtPeriodeAkhir" />
        </td>
    </tr>
    <tr>
            <td colspan="2">
                &nbsp;
            </td>
            <td>
                <div style="text-align: right; padding-top: 10px;">
                    <button class="dialog_link ui-state-default ui-corner-all" id="btnNext" type="button">Lanjut</button>
                    <button class="dialog_link ui-state-default ui-corner-all" id="btnCancel" type="button">Batal</button>
                </div>
            </td>
        </tr>
</table>
<div>
        <asp:ScriptManager ID="scManager" runat="server" EnablePartialRendering="true">
        </asp:ScriptManager>
        <rsweb:reportviewer  ID="rsViewer" runat="server" Height="100%" Width="100%">
        </rsweb:reportviewer>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            var countSektor = 0;
            var countSubSektor = 0;
            var countSubSubSektor = 0;

            $('#txtSektor').val('pilih sektor...');
            $('#txtSubSektor').val('pilih sub sektor...');
            $('#txtSubSubSektor').val('pilih sub sub sektor...');

            $('#txtSektor').focus(function () {
                if (countSektor == 0) {
                    $('#txtSektor').val('');
                    countSektor++;
                }
            });

            $('#txtSubSektor').focus(function () {
                if (countSubSektor == 0) {
                    $('#txtSubSektor').val('');
                    countSubSektor++;
                }
            });

            $('#txtSubSubSektor').focus(function () {
                if (countSubSubSektor == 0) {
                    $('#txtSubSubSektor').val('');
                    countSubSubSektor++;
                }
            });


            $("#myClass2").hide();
            $('#cbDetail').change(function () {
                if ($(this).is(':checked')) {
                    $("#myClass1").hide();
                    $("#myClass2").show();
                } else {
                    $("#myClass2").hide();
                    $("#myClass1").show();
                }
            });

            $("#txtPeriodeAwal").datepicker({ showWeek: true, showButtonPanel: true,
                changeMonth: true, changeYear: true, dateFormat: 'dd/mm/yy',
                numberOfMonths: 1,
                onSelect: function (selected) {
                    $("#txtPeriodeAkhir").datepicker("option", "minDate", selected)
                }
            });

            $("#txtPeriodeAkhir").datepicker({ showWeek: true, showButtonPanel: true,
                changeMonth: true, changeYear: true, dateFormat: 'dd/mm/yy',
                numberOfMonths: 1,
                onSelect: function (selected) {
                    $("#txtPeriodeAwal").datepicker("option", "maxDate", selected)
                }
            });

            function pisahkan(control) {
                var list = control;
                var a = "";
                var temp = [];
                var temp1 = [];
                temp = list.split(',');
                if (temp.length > 0) {
                    for (i = 0; i < temp.length - 1; i++) {
                        a = "\'" + temp[i].split('-', 1) + "\'";
                        temp1.push(a);
                    }
                }
                var gabung = temp1.join(',');
                return gabung;
            }

            $('#btnNext').click(function () {
                var sectorID = $('#txtSektor').val();
                var subSectorID = $('#txtSubSektor').val();
                var subSubSectorID = $('#txtSubSubSektor').val();
                var transTypeID = $('#<%= ddlJenisPungutan.ClientID %>').val();
                var periodeAwal = $('#txtPeriodeAwal').val();
                var periodeAkhir = $('#txtPeriodeAkhir').val();
                var detail = 0;

                if ($('#cbDetail').is(':checked'))
                    detail = 1;

                var listSectorID = pisahkan($('#txtSektor').val());
                var listSubSectorID = pisahkan($('#txtSubSektor').val());
                var listSubSubSectorID = pisahkan($('#txtSubSubSektor').val());
                //alert(listSectorID);
                window.location = "rptIncome.aspx?SectorID=" + listSectorID + "&SubSectorID=" + listSubSectorID + "&SubSubSectorID=" + listSubSubSectorID + "&TransTypeID=" + transTypeID + "&PeriodeAwal=" + periodeAwal + "&PeriodeAkhir=" + periodeAkhir + "&Detail=" + detail;
            });
        });
    </script>
</asp:Content>

